package cn.credit.loan.controller;

import java.util.List;

import org.apache.commons.lang3.CharUtils;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
/**
 * 黑名单控制类
 * @author 
 *
 */
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import cn.credit.loan.entity.Blacklistuser;
import cn.credit.loan.service.blacklistuser.BlacklistuserService;
@Controller
public class BlacklistuserController {
	//日志输出
	private Logger logger = Logger.getLogger(BlacklistuserController.class);
	@Autowired
	private BlacklistuserService  blacklistuserService;
	
	/**
	 * 黑名单添加
	 * @param blacklistuser
	 * @param model
	 * @return
	 */
	@RequestMapping("/blacklistuseradd")
	public String getBlacklistuserAdd(Blacklistuser blacklistuser,ModelMap model)
	{
		 
		try {
			
			blacklistuser.setBlacklistSex(CharUtils.toCharacterObject("男"));
			blacklistuser.setBlacklistIDcardNo("123456789987654321");
			blacklistuser.setBlacklistAge(20);
			blacklistuser.setBlacklistPhone("12345678901");
			blacklistuser.setBlacklistAddress("佛山");
			blacklistuser.setCompanyPhone("12345678910");
			blacklistuser.setDoesitbelongto("信用不行");
			blacklistuser.setHomePhone("1234567");
			boolean	blacklistusers = blacklistuserService.blacklistuserAdd(blacklistuser);
			if(blacklistusers){
				model.addAttribute("blacklistuser", blacklistuser);
				return "BlacklistuserAdd";
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return null;
		
	}
	/**
	 * 黑名单更新
	 * @param blacklistuser
	 * @param model
	 * @return
	 */
	@RequestMapping("/blacklistuserupdate")
	public String getBlacklistuserUpdate(Blacklistuser blacklistuser,ModelMap model)
	{
		 
		try {
			blacklistuser.setBlacklistName("测试005");
			blacklistuser.setBlacklistSex(CharUtils.toCharacterObject("女"));
			blacklistuser.setBlacklistIDcardNo("123456789987654321");
			blacklistuser.setBlacklistAge(20);
			blacklistuser.setBlacklistPhone("12345678901");
			blacklistuser.setBlacklistAddress("佛山");
			blacklistuser.setCompanyPhone("12345678910");
			blacklistuser.setDoesitbelongto("信用不行");
			blacklistuser.setHomePhone("1234567");
			boolean	blacklistusers = blacklistuserService.blacklistuserUpdate(blacklistuser);
			if(blacklistusers){
				model.addAttribute("blacklistuser", blacklistuser);
				return "BlacklistuserUpdate";
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return null;
		
	}
	
	
	/**
	 * 黑名单删除
	 * @param blacklistId
	 * @param model
	 * @return
	 */
	@RequestMapping("/blacklistuserdelete")
	public String getBlacklistuserDelete(int blacklistId,ModelMap model)
	{
		 
		try {
			boolean	blacklistusers = blacklistuserService.blacklistuserDelete(blacklistId);
			if(blacklistusers){
				model.addAttribute("blacklistId", blacklistId);
				return "BlacklistuserDelete";
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return null;
		
	}
	/**
	 * 黑名单查询
	 * @param blacklistuser
	 * @param model
	 * @return
	 */
	@RequestMapping(value="/blacklistuserlist")
	@ResponseBody
	public Object getBlacklistuserList(Blacklistuser blacklistuser,ModelMap model)
	{
		try {
			List<Blacklistuser> blacklist=blacklistuserService.getBlacklistuserList(blacklistuser);
			if(blacklist!=null)
			{
				model.addAttribute("blacklistuser", blacklistuser);
				return blacklist;
			}
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}
}
